﻿using System;
using System.Web;
using System.IO;
using VioletDevelopmentLaboratory.Net.Web.Component;
using VioletDevelopmentLaboratory.Net.Web.Configuration;

namespace VioletDevelopmentLaboratory.Net.Web
{
	public class MemberImageViewerHandlerBase : IHttpHandler
	{
		public Boolean IsReusable { get { return false; } }

		public void ProcessRequest(HttpContext context)
		{
			if (context == null)
				throw new ArgumentNullException("context");

			String providerUserKey = context.Server.UrlDecode(context.Request.QueryString["key"]);

			if (!String.IsNullOrEmpty(providerUserKey))
			{
				MemberImageFileInfo memberImageFileInfo = MemberImageFileInfo.GetMemberImageFileInfo(providerUserKey);

				if (memberImageFileInfo != null && File.Exists(memberImageFileInfo.PhysicalFilePath))
					context.Response.TransmitFile(memberImageFileInfo.PhysicalFilePath);
				else
					context.Response.TransmitFile(context.Server.MapPath(VUtility.GetVWebGlobalResource("General_DefaultUserImage")));
			}
		}
	}
}
